<!DOCTYPE html>
<html >
<head>
    <meta charset="utf-8">
    <title>分类添加</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport"
          content="width=device-width, initial-scale=1, maximum-scale=1">
    <meta name="apple-mobile-web-app-status-bar-style" content="black">
    <meta name="apple-mobile-web-app-capable" content="yes">
    <meta name="format-detection" content="telephone=no">
    <link rel="stylesheet" href="/layui/css/layui.css" media="all"/>
    <link rel="stylesheet" href="/css/font_eolqem241z66flxr.css"
          media="all"/>
</head>
<body>

<form class="layui-form" lay-filter="formtable">

    <div class="layui-form-item">
        <label class="layui-form-label">名称:</label>
        <div class="layui-input-block text1">
            <input type="text" name="name" class="layui-input"
                   lay-verify="required" placeholder="请输入">
            <input type="hidden" name="id" id="id">
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">类型</label>
        <div class="layui-input-block text1">
            <input type="text" name="type" class="layui-input"
                   lay-verify="required" placeholder="请输入">
        </div>
    </div>

    <div class="layui-form-item">
        <div class="layui-input-block">
            <button class="layui-btn" lay-submit="" lay-filter="adddd">立即提交</button>
            <button type="reset" class="layui-btn layui-btn-primary">重置</button>
        </div>
    </div>
</form>
<script type="text/javascript" src="/layui/layui.js"></script>

<script type="text/javascript" >

     layui
         .use(
             ['form', 'layer', 'jquery', 'layedit', 'laydate', 'upload'],
             function () {
                 var form = layui.form, layer = layui.layer, laypage = layui.laypage, layedit = layui.layedit,
                     laydate = layui.laydate, $ = layui.jquery, upload = layui.upload;

                 function getUParam(name, id) {
                     var reg = new RegExp("(^|&)" + name + "=([^&]*)(&|$)"); // 构造一个含有目标参数的正则表达式对象
                     var r = decodeURIComponent(
                         $("#" + id).attr("src").substr(
                             $("#" + id).attr("src").indexOf("?"))
                             .substr(1)).match(reg); // 匹配目标参数
                     if (r != null)
                         return unescape(r[2]);
                     return ""; // 返回参数值
                 }

                 var id="[[${modyid}]]";
                 console.log("controller的id值="+id)

                 // 监听提交
                 form.on('submit(adddd)', function (data) {
                     console.log("监听到的数据为："+data)
                     parent.resetSwClose(true);
                     layer.msg('正在保存...', {time: 1000}, function () {
                     });
                     var url = "";
                     if (id !="")
                         url = "/log/update";
                     else
                         url = "/log/add";

                     console.log("请求地址为："+url)
                     $.getJSON(url, data.field,

                         function (data) {

                         console.log("是否执行该行")
                             if (data.code == '200') {
                                 parent.layer.closeAll();
                                 parent.reloadList();
                             } else {
                                 layer.msg('数据保存失败', {
                                     time: 1000
                                 }, function () {
                                     alert(300)
                                 });
                                 parent.resetSwClose(false);
                             }
                         });
                     return false;
                 });

                 //获取信息
                 if (id != null && id != '') {
                     $.getJSON("/log/get", "id=" +id , function (jsondata) {
                      console.log( jsondata.code)
                         console.log("是否输出这一行")
                      console.log(jsondata.data)
                         if (jsondata.code == '200') {
                             console.log(jsondata.code)
                             //表单初始赋值
                             form.val('formtable',JSON.parse(JSON.stringify(jsondata.data)) );
                         } else {
                             $("#subpost").attr("disabled", "disabled").addClass("layui-btn-disabled");
                             layer.msg(jsondata.msg, {time: 2000}, function () {
                                 parent.layer.closeAll('iframe');
                             });
                         }
                     });
                 }


             })

</script>
</body>
</html>